#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MY_MAX_RAND 20
#define MY_ARRAY_SIZE 20000000
#define MY_SWAP_COUNT 100000

typedef struct
{
	int int_array[MY_ARRAY_SIZE];
} testArray;

typedef struct
{
	int counts[MY_MAX_RAND];
} resultArray;




void outResults(resultArray* the_results)
{
	int i = 0;
	for (i = 0; i < MY_MAX_RAND; i++)
	{
		printf("%6d: %6d\n", i, the_results->counts[i]);
	}
	return;
}



int main(void)
{
	testArray* the_array = (testArray *)malloc(sizeof(testArray));
	resultArray* results = (resultArray *)malloc(sizeof(resultArray));

	struct timespec tp;
	clock_gettime ( CLOCK_REALTIME, &tp );

//		time_t seconds = tp.tv_sec;
	long int nanoseconds1 = tp.tv_nsec;
	printf("%ld\n", nanoseconds1);

	int i = 0;
	for (i = 0; i < MY_ARRAY_SIZE; i++)
	{
		the_array->int_array[i] = rand() % MY_MAX_RAND;
//		printf("%d\n", the_array->int_array[i]);

		results->counts[the_array->int_array[i]] += 1;

	}

	struct timespec tp2;
	clock_gettime ( CLOCK_REALTIME, &tp2 );

//		time_t seconds = tp.tv_sec;
	long int nanoseconds2 = tp2.tv_nsec;

	outResults(results);
	printf("Nanoseconds to complete: %ld\n", nanoseconds2 - nanoseconds1);


	return 0;
}
